﻿
@{
    Layout = null;
	Layout = "~/Views/Shared/PageTemplate.cshtml";

}






    <link rel="stylesheet" href="/zTree_v3/css/demo.css" type="text/css">
    <link rel="stylesheet" href="/zTree_v3/css/zTreeStyle/zTreeStyle.css" type="text/css">
    <script type="text/javascript" src="/zTree_v3/js/jquery-1.4.4.min.js"></script>
    <script type="text/javascript" src="/zTree_v3/js/jquery.ztree.core.js"></script>
    <script type="text/javascript" src="/zTree_v3/js/jquery.ztree.excheck.js"></script>
    <!--
    <script type="text/javascript" src="/zTree_v3/js/jquery.ztree.exedit.js"></script>
    -->
    <SCRIPT type="text/javascript">
		<!--
		var setting = {
			check: {
				enable: true
			},
			data: {
				simpleData: {
					enable: true
				}
			},
			async: {
			    //异步加载
			    enable: true,
			    url: "ListZTreeData",
			    contentType: "application/json",
			    type: "post",
			    autoParam: ["id"]
			}
		};

		var zNodes =[
			{ id:1, pId:0, name:"随意勾选 1", open:true},
			{ id:11, pId:1, name:"随意勾选 1-1", open:true},
			{ id:111, pId:11, name:"随意勾选 1-1-1"},
			{ id:112, pId:11, name:"随意勾选 1-1-2"},
			{ id:12, pId:1, name:"随意勾选 1-2", open:true},
			{ id:121, pId:12, name:"随意勾选 1-2-1"},
			{ id:122, pId:12, name:"随意勾选 1-2-2"},
			{ id:2, pId:0, name:"随意勾选 2", checked:true, open:true},
			{ id:21, pId:2, name:"随意勾选 2-1"},
			{ id:22, pId:2, name:"随意勾选 2-2", open:true},
			{ id:221, pId:22, name:"随意勾选 2-2-1", checked:true},
			{ id:222, pId:22, name:"随意勾选 2-2-2"},
			{ id:23, pId:2, name:"随意勾选 2-3"}
		];

		var code;

		function setCheck() {
			var zTree = $.fn.zTree.getZTreeObj("treeDemo"),
			py = $("#py").attr("checked")? "p":"",
			sy = $("#sy").attr("checked")? "s":"",
			pn = $("#pn").attr("checked")? "p":"",
			sn = $("#sn").attr("checked")? "s":"",
			type = { "Y":py + sy, "N":pn + sn};
			zTree.setting.check.chkboxType = type;
			showCode('setting.check.chkboxType = { "Y" : "' + type.Y + '", "N" : "' + type.N + '" };');
		}
		function showCode(str) {
			if (!code) code = $("#code");
			code.empty();
			code.append("<li>"+str+"</li>");
		}

		$(document).ready(function(){
		    //$.fn.zTree.init($("#treeDemo"), setting, zNodes);
		    createTree();
			setCheck();
			$("#py").bind("change", setCheck);
			$("#sy").bind("change", setCheck);
			$("#pn").bind("change", setCheck);
			$("#sn").bind("change", setCheck);
		});


		function createTree() {

		    $.ajax({
		        url: 'ListZTreeData', //url  action是方法的名称
		        data: { id: "",rguid:"@Context.Request.Query["rguid"]" },
		        type: 'Post',
		        dataType: "text", //可以是text，如果用text，返回的结果为字符串；如果需要json格式的，可是设置为json
		        success: function (data) {
		            $.fn.zTree.init($("#treeDemo"), setting, eval('(' + data + ')'));
		        },
		        error: function (msg) {
		            // alert(" 数据加载失败！" + msg);
		        }
		    });
		}

		function GetCheckedAll() {
            //获取所有值
		    var treeObj = $.fn.zTree.getZTreeObj("treeDemo");
		    var nodes = treeObj.getCheckedNodes(true);
		    //var msg = "name--id--pid\n";
		    var menuguid = "";
		    for (var i = 0; i < nodes.length; i++) {
		        menuguid +=","+  nodes[i].id;
		    }
		    window.parent.opener.document.getElementById("hid_MenuGuid").value = menuguid;
		    window.close();
		  //  $("#msg").val();
		    //$("#msg").val(msg);
		    // alert(msg);
		}
		//-->
    </SCRIPT>

    
    <div style="text-align:center"><input id="inp_tvalue" type="button" onclick="GetCheckedAll()" value="确定配置" style="margin-top:10px;" /></div>
    <div class="content_wrap" style="width:380px;margin:0 auto;">
        <div class="zTreeDemoBackground left" style="width:380px;">
            <ul id="treeDemo" class="ztree" style="width:370px;height:430px;"></ul>
        </div>

    </div>
